/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Servlet.home;

import Logger.MyLogger;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author marcello
 */
public class Homepage extends HttpServlet {

    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        String path = request.getContextPath();
        path += "/";
        MyLogger.getLogger().debug("Servlet Home");
        PrintWriter out = response.getWriter();
        try {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<link href='http://fonts.googleapis.com/css?family=Quicksand:300,400' rel='stylesheet' type='text/css' /> "
                    + "<link href=\"" + path + "css/smoothness/jquery-ui-1.8.16.custom.css\" type=\"text/css\" rel=\"stylesheet\"  />"
                    + "<link href=\"" + path + "css/stile.css\" type=\"text/css\" rel=\"stylesheet\" />"
                    + "<script src=\"" + path + "js/jquery-1.6.2.min.js\" ></script>"
                    + "<script src=\"" + path + "js/jquery-ui-1.8.16.custom.min.js\" ></script>"
                    + "<script src=\"" + path + "js/sha1.js\" ></script>"
                    + "<style>"
                    + "*{font-family: 'Quicksand', sans-serif; }"
                    + "</style>"
                    + "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
                    + "<title>Portale Vaccinazioni</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<div id='cont'> "
                    + "<header>"
                    + "Portale Vaccinazioni"
                    + "</header>"
                    + "<div id='accordion'>"
                    + "<h3><a href='#'>Login Medici</a></h3>"
                    + "<div>"
                    + "<form action='protected/medic/welcome_medic.jsp' method='post' onsubmit='digest1()'>"
                    + "<table>"
                    + "<tbody>"
                    + "<tr>"
                    + "<td><label for='username'>Username:</label></td>"
                    + "<td><input name='username' id='username' required='required' /></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><label for='password1'>Password:</label></td>"
                    + "<td><input name='password' type='password' id='password1' required='required'/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><input type='reset' value='Cancella campi' /></td>"
                    + "<td><input type='submit' value='Login'/></td>"
                    + "</tr>"
                    + "</tbody>"
                    + "</table>"
                    + "</form>"
                    + "</div>"
                    + "<h3><a>Login Utente</a></h3>"
                    + "<div>"
                    + "<form action='protected/paziente/welcomePaziente' method='post' onsubmit='digest2()'>"
                    + "<table>"
                    + "<tbody>"
                    + "<tr>"
                    + "<td><label for='username'>Username:</label></td>"
                    + "<td><input name='username' id='username' required='required' /></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><label for='password2'>Password:</label></td>"
                    + "<td><input name='password' type='password' id='password2' required='required'/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><input type='reset' value='Cancella campi' /></td>"
                    + "<td><input type='submit' value='Login'/></td>"
                    + "</tr>"
                    + "</tbody>"
                    + "</table>"
                    + "</form>"
                    + "</div>"
                    + "<h3><a>Registrazione Utente</a></h3>"
                    + "<div>"
                    + "<form action='RegistrazionePaziente' method='post' onsubmit='digest3()' >"
                    + "<table style=\"float: left;\"><tbody>"
                    + "<tr>"
                    + "<td><label for='nome'>Inserisca il suo nome:</label></td>"
                    + "<td><input name='nome' type='text' id='nome' required='required'/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><label for='cognome'>Inserisca il suo cognome:</label></td>"
                    + "<td><input name='cognome' type='text' id='cognome' required='required'/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><label for='username'>Seleziona username:</label></td>"
                    + "<td><input name='username' id='username' required='required' /></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><label for='password3'>Seleziona password:</label></td>"
                    + "<td><input name='password' type='password' id='password3' required='required'/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><img src=\"jcaptcha.jpg\" style=\"border: 1px solid black;\"/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><label for='jcaptcha'>Inserisca il testo dell'immagine:</label></td>"
                    + "<td><input type=\"text\" name=\"jcaptcha\" id='jcaptcha' value=\"\" required=\"required;\"/></td>"
                    + "</tr>"
                    + "<tr>"
                    + "<td><input type='submit' value='Resgistrati'/></td>"
                    + "</tr>"
                    + "</tbody></table>"
                    + "</form>"
                    + "</div>"
                    + "</div>"
                    + "</div>"
                    + "<script>"
                    + "$('#accordion').accordion({active: 0, collapsible: true});"
                    //Digest della password tramite algoritmo SHA1 per non inviarla in chiaro
                    + "function digest1(){"
                    + "$('#password1').val(SHA1($('#password1').val()));"
                    + "}"
                    + "function digest2(){"
                    + "$('#password2').val(SHA1($('#password2').val()));"
                    + "}"
                    + "function digest3(){"
                    + "$('#password3').val(SHA1($('#password3').val()));"
                    + "}"
                    + "</script>");
            out.println("</body>");
            out.println("</html>");

        } finally {
            out.close();
        }
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
